package com.ylbh.modules.outerchain.controller;

import java.util.Arrays;
import java.util.List;

import com.ylbh.common.annotation.SysLog;
import com.ylbh.common.utils.*;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.ylbh.modules.outerchain.entity.ShoppingOuterChain;
import com.ylbh.modules.outerchain.service.ShoppingOuterChainService;


/**
 * 平台外链地址管理
 *
 * @author czx
 * @date 2019-11-29 16:38:58
 */
@RestController
@RequestMapping("outer")
public class ShoppingOuterChainController {

    @Autowired
    private ShoppingOuterChainService shoppingOuterChainService;

    @ApiOperation("外链管理列表")
    @GetMapping("/queryOuterChainList")
//    @RequiresPermissions("outerChain:queryOuterChainList")
    public CommonResult queryOuterChainList(PageDTO dto){
        PageUtils page = shoppingOuterChainService.queryOuterChainList(dto);
        return Ref.ok(page);
    }


    @ApiOperation("外链详情")
    @GetMapping("/getOuterChainById/{id}")
//    @RequiresPermissions("outerChain:getOuterChainById")
    public CommonResult getOuterChainById(@PathVariable("id") Long id){
		ShoppingOuterChain shoppingOuterChain = shoppingOuterChainService.getOuterChainById(id);
        return Ref.ok(shoppingOuterChain);
    }

    @SysLog("修改外链")
    @ApiOperation("修改外链")
    @PostMapping("/modifyOuterChainById")
//    @RequiresPermissions("outerChain:modifyOuterChainById")
    public CommonResult modifyOuterChainById(@RequestBody ShoppingOuterChain shoppingOuterChain){
		shoppingOuterChainService.modifyOuterChainById(shoppingOuterChain);
        return Ref.ok();
    }

    @SysLog("增加外链")
    @ApiOperation("增加外链")
    @PostMapping("/addOuterChain")
//    @RequiresPermissions("outerChain:addOuterChain")
    public CommonResult addOuterChain(@RequestBody ShoppingOuterChain shoppingOuterChain){
		shoppingOuterChainService.addOuterChain(shoppingOuterChain);
        return Ref.ok();
    }

    @SysLog("删除外链")
    @ApiOperation("删除外链")
    @PostMapping("/removeOuterChain")
//    @RequiresPermissions("outerChain:removeOuterChain")
    public CommonResult removeOuterChain(@RequestBody Long[] ids){
		shoppingOuterChainService.removeOuterChain(Arrays.asList(ids));
        return Ref.ok();
    }

    @SysLog("修改外链启用状态")
    @ApiOperation("修改外链启用状态")
    @PostMapping("modifyIsEnableById/{id}/{isEnable}")
    public CommonResult modifyIsEnableById(@PathVariable Long id, @PathVariable Integer isEnable) {
        shoppingOuterChainService.modifyIsEnableById(id, isEnable);
        return Ref.ok();
    }

    @ApiOperation("外链下级列表")
    @GetMapping("/queryOuterChainSubordinateList")
    public CommonResult queryOuterChainSubordinateList(PageDTO dto){
        PageUtils page = shoppingOuterChainService.queryOuterChainSubordinateList(dto);
        return Ref.ok(page);
    }

    @ApiOperation("活动下拉")
    @GetMapping("/queryActivityOuterChainList")
    public CommonResult queryActivityOuterChainList(){
        List<ShoppingOuterChain> list = shoppingOuterChainService.queryActivityOuterChainList();
        return Ref.ok(list);
    }

}
